package com.zeroxml.cms.dao.impl;

import com.zeroxml.cms.bo.Comment;
import com.zeroxml.cms.dao.ICommentDAO;
import com.wyvoid.core.persistent.hibernate.HibernateDAO;
import com.wyvoid.core.persistent.hibernate.HibernatePage;

import java.util.List;

/**
 * User: cjp
 * Date: 2007-9-20
 * Time: 9:14:50
 */
public class CommentDAO extends HibernateDAO<Comment> implements ICommentDAO {
    public HibernatePage<Comment> getComments(long articleId, int curPage, int pageSize) {
        String hql = "from Comment where 1=1 ";
        if (articleId > 0) {
            hql += " and article.id=? ";
        }
        hql += "order by createTime desc";
        if (articleId > 0) {
            return new HibernatePage<Comment>(hql, this.getSession(), true, curPage, pageSize, articleId);
        }else{
            return new HibernatePage<Comment>(hql, this.getSession(), true, curPage, pageSize);
        }
    }

    public List<Comment> getLatestComments(int size) {
        String hql = "from Comment order by createTime desc";
        return doQueryLimitList(hql, true, size);
    }
}
